home *** CD-ROM | disk | FTP | other *** search
/ Family Forum 261 / SOMC Family Forum 261.iso / Xtras / Animation Wizard.dir / 00008_Script_Banners < prev    next >
Text File  |  1997-05-10  |  10KB  |  345 lines

  1. -- Banners script
  2.  
  3. property ioFieldList
  4. property iFieldFocus
  5. property ioFieldFocus
  6. property iCurrentMotionStyleIndex
  7. property iCurrentVisualStyleIndex
  8.  
  9. -- The motion styles are:
  10. property ikMotionRightToLeft  -- 1
  11. property ikMotionLeftToRight  -- 2
  12. property ikMotionUp                 -- 3
  13. property ikMotionDown             --4
  14.  
  15. property iFirstTIme
  16. property iSaveSeconds
  17. property iSaveFPS
  18. property iSaveBaseline
  19. property iSaveDelayEnter
  20. property iSaveMark
  21. property iSaveCycles
  22.  
  23.  
  24. on birth me
  25.   global goBannersText
  26.   global goSeconds
  27.   global goFPS
  28.   global goBaseLine
  29.   global goDelayEnter
  30.   global goCycles
  31.   
  32.   set ioFieldList = [goBannersText, goSeconds, goFPS, goBaseLine, goDelayEnter, goCycles]
  33.   set ikMotionRightToLeft = 1
  34.   set ikMotionLeftToRight = 2
  35.   set ikMotionUp = 3
  36.   set ikMotionDown = 4
  37.   
  38.   set iCurrentMotionStyleIndex = ikMotionRightToLeft
  39.   set iCurrentVisualStyleIndex = 1
  40.   set iFieldFocus = 1
  41.   set iFirstTime = TRUE
  42.   
  43.   return me
  44. end birth
  45.  
  46. on mInit me
  47.   global goSeconds
  48.   global goFPS
  49.   global goBaseLine
  50.   global goDelayEnter
  51.   global goCycles
  52.   global goBanners
  53.   global goMarkFrame
  54.   global goVisualStyles
  55.   global goMotionStyles
  56.   global goScoreMgr
  57.   
  58.   -- CheckMark parameter: channel
  59.   mInit(goMarkFrame, 4)  -- channel
  60.   
  61.   if iFirstTime then  -- use intellegent defaults
  62.     mSetValue(goSeconds, 5)
  63.     mSetValue(goFPS, 5)
  64.     set defaultBaseLine = integer(mGetStageHeight(goScoreMgr) / 2)
  65.     mSetValue(goBaseLine, defaultBaseLine)
  66.     mSetValue(goDelayEnter, 0)
  67.     mSetValue(goCycles, 1)
  68.     mSetValue(goMarkFrame, TRUE)
  69.     set iFirstTime = FALSE
  70.     
  71.   else  -- use values saved from when we last left
  72.     mSetValue(goSeconds, iSaveSeconds)
  73.     mSetValue(goFPS, iSaveFPS)
  74.     mSetValue(goBaseLine, iSaveBaseline)
  75.     mSetValue(goDelayEnter, iSaveDelayEnter)
  76.     mSetValue(goCycles, iSaveCycles)
  77.     mSetValue(goMarkFrame, iSaveMark)
  78.   end if
  79.   
  80.   set ioFieldFocus = GetAt(ioFieldList, iFieldFocus)
  81.   
  82.   -- RadioButtons parameters: channel, nChannels, rightAnswer, default
  83.   set goMotionStyles = 0
  84.   set goMotionStyles = birth(script "RadioButton",  26, 4, 0, iCurrentMotionStyleIndex)
  85.   
  86.   
  87.   -- VisualStyles Params: castNum, default, nItems, channel
  88.   if the machineType < 256 then
  89.     mInit(goVisualStyles, the number of cast "BannersVisualStylesMac", ¼
  90.                iCurrentVisualStyleIndex, 8, 19)
  91.   else
  92.     mInit(goVisualStyles, the number of cast "BannersVisualStylesPC", ¼
  93.                iCurrentVisualStyleIndex, 8, 19)
  94.   end if
  95.   
  96.   
  97.   -- For keystroke validity checking
  98.   set the keydownscript =  "mCheckKey(goBanners)"
  99.   
  100. end mInit 
  101.  
  102. on mSetFieldFocus me, oWhom
  103.   set where = getOne(ioFieldList, oWhom)
  104.   if where = 0 then
  105.     alert("Internal error - mSetFieldFocus could not find object")
  106.     return
  107.   end if
  108.   
  109.   set iFieldFocus = where  
  110.   set ioFieldFocus = GetAt(ioFieldList, iFieldFocus)
  111.   
  112. end mSetFieldFocus
  113.  
  114.  
  115. on mCheckKey me
  116.   if the Key = TAB then -- change focus to the next field
  117.     set iFieldFocus = IncrMod(iFieldFocus, count(ioFieldList))
  118.     set ioFieldFocus = GetAt(ioFieldList, iFieldFocus)
  119.     pass  -- pass the event so the hilight goes to the next field  
  120.   else
  121.     if iFieldFocus = 1 then -- the text entry field, allow anything
  122.       pass
  123.     else  -- numeric fields, only allow digits
  124.       if (offset(the key, "0123456789") > 0) or (the key = BACKSPACE)  then
  125.         pass
  126.       else
  127.         dontPassEvent -- restrict only to digits.
  128.       end if
  129.     end if
  130.   end if
  131. end mCheckKey
  132.  
  133. on mSetNewMotionStyle me, theNewStyleIndex
  134.   set iCurrentMotionStyleIndex = theNewStyleIndex
  135. end mSetNewMotionStyle
  136.  
  137. on mSetNewVisualStyle me, theNewStyleIndex
  138.   set iCurrentVisualStyleIndex = theNewStyleIndex
  139. end mSetNewVisualStyle
  140.  
  141.  
  142.  
  143. on mValidate me
  144.   -- Attempt to validate the last field of focus
  145.   set lastFieldOKFlag = mValidate(ioFIeldFocus)
  146.   return lastFieldOKFlag
  147. end mValidate
  148.  
  149.  
  150. on mCreate me
  151.   global goMarkFrame
  152.   global goMotionStyles
  153.   global goVisualStyles
  154.   global goScoreMgr
  155.   global goCastMgr
  156.   global gDevelopmentFlag
  157.   global gCastNumTextAsBitmap
  158.   global goPlatform
  159.   
  160.   if not(mValidate(me)) then
  161.     return
  162.   end if
  163.   if field("BannersText") = EMPTY then
  164.     alert("Please enter some text for the banner.")
  165.     return
  166.   end if
  167.   
  168.   tell the stage
  169.     set theStageFrame = the frame
  170.   end tell
  171.   
  172.   set castNumVisualStyle = mGetCastNum(goVisualStyles, iCurrentVisualStyleIndex)
  173.   set theVisualStyleName = the name of cast castNumVisualStyle
  174.   set theFont = word 2 of theVisualStyleName
  175.   set theSize = word 3 of theVisualStyleName
  176.   set theSeconds = integer(field "Seconds")
  177.   
  178.   set fps = integer(field "FPS")
  179.   set nFrames = integer(theSeconds * fps)
  180.   set baseLine = integer(field "BaseLine")
  181.   set delayEnter = integer(field "DelayEnter")
  182.   set nCycles = integer(field "Cycles")
  183.   set markFirst = mGetValue(goMarkFrame)
  184.   
  185.   
  186.   -- Call the ScoreMgr to set up the score, # of frames, and 1 channel
  187.   --  set nTotalFrames = (delayEnter + nFrames) * nCycles 
  188.   set nTotalFrames = nFrames * nCycles 
  189.   if not(mInit(goScoreMgr, nTotalFrames, 1)) then
  190.     return
  191.   end if
  192.   
  193.   set theCh = mGetNextSelectedChannel(goScoreMgr)
  194.   set theFrameNum = mGetStartFrame(goScoreMgr)
  195.   
  196.   set castNumSource = mModifyRichTextCM(goCastMgr, ¼
  197.                 the text of field "BannersText", theFont, theSize)
  198.   if castNumSource = 0 then  -- error
  199.     return
  200.   end if
  201.   
  202.   -- The following does an effective "Convert to bitmap" into a 
  203.   -- known bitmap cast member.
  204.   set the picture of member gCastNumTextAsBitmap = ¼
  205.         the picture of member castNumSource
  206.   set widthOfTextAsBitmap = the width of member gCastNumTextAsBitmap
  207.   set heightOfTextAsBitmap = the height of member castNumSource / ¼
  208.                                                 the number of lines in (the text of member castNumSource)
  209.   
  210.   
  211.   -- Do specific calculations depending on motion style  
  212.   
  213.   if (iCurrentMotionStyleIndex = ikMotionRightToLeft) or ¼
  214.       (iCurrentMotionStyleIndex = ikMotionLeftToRight) then    
  215.     set yStart = baseline
  216.     set yEnd = baseLine
  217.     set yInc = 0
  218.     
  219.     if (iCurrentMotionStyleIndex = ikMotionRightToLeft)  then   
  220.       set xStart = mGetStageRight(goScoreMgr)  + 10
  221.       set xEnd = 0 - widthOfTextAsBitmap - 10  
  222.       set xInc = float( xEnd - xStart ) / float(nFrames)  
  223.       
  224.     else  -- Left to right
  225.       set xStart = 0 - widthOfTextAsBitmap - 10  
  226.       set xEnd = mGetStageRight(goScoreMgr) + 10       
  227.       set xInc = float( xEnd - xStart ) / float(nFrames)     
  228.     end if
  229.     
  230.   else  -- up or down
  231.     set xStart = (mGetStageWidth(goScoreMgr) / 2) - (widthOfTextAsBitmap / 2)
  232.     set xEnd = xStart
  233.     set xInc = 0
  234.     if (iCurrentMotionStyleIndex = ikMotionUp)  then   
  235.       set yStart = mGetStageHeight(goScoreMgr) + heightOfTextAsBitmap + 1
  236.       set yEnd = 0 - heightOfTextAsBitmap - 10 
  237.       set yInc = float( yEnd - yStart ) / float(nFrames)  
  238.       
  239.     else  -- Down
  240.       set yStart = 0 - heightOfTextAsBitmap - 10  
  241.       set yEnd = mGetStageHeight(goScoreMgr) + heightOfTextAsBitmap + 10       
  242.       set yInc = float( yEnd - yStart ) / float(nFrames)  
  243.       
  244.     end if
  245.   end if
  246.   
  247.   set theForeColor  = 255
  248.   set theBackColor  = 0
  249.   
  250.   --  Copy the cast member into the source movie's cast
  251.   
  252.   set castNumTarget = mFindFreeCastRun(goCastMgr, 1, 1)
  253.   copyToClipBoard member castNumSource
  254.   tell the stage
  255.     pasteClipboardInto member castNumTarget
  256.     set the name of member castNumTarget  = "RichText" && string(the ticks)
  257.   end tell
  258.   
  259.   --  Finally we are ready to generate frames
  260.   
  261.   -- initialize list of frames to record in
  262.   set frameList  = []
  263.   repeat with i = theFrameNum  to  (theFrameNum + nTotalFrames  - 1)
  264.     add(frameList, [i])
  265.   end repeat
  266.   
  267.   
  268.   -- Mark first frame upon request
  269.   if markFirst  then
  270.     set firstFrame= getAt(frameList, 1)
  271.     set theLabel  = "AW.Banner." & word 1 of the text of field "BannersText" & " " & ¼
  272.               mGetGeneratedScoreSelection(goScoreMgr)
  273.     add(firstFrame,  [#label, theLabel])
  274.     setAt(frameList, 1, firstFrame)
  275.   end if
  276.   set relFrameCount = 1
  277.   
  278.   -- Generate the score fragment
  279.   repeat with thisCycle = 1 to nCycles
  280.     set firstFrame = getAt( frameList, relFrameCount)
  281.     set secondFrame = getAt( frameList, relFrameCount + 1)
  282.     if delayEnter > 0 then
  283.       add(firstFrame, [#tempo, -delayEnter])
  284.       add(secondFrame, [#tempo, fps])
  285.     else 
  286.       add(firstFrame, [#tempo, fps])
  287.       add(secondFrame, [#tempo, 0])
  288.     end if
  289.     setAt(frameList, relFrameCount, firstFrame)
  290.     setAt(frameList,relFrameCount + 1, secondFrame)
  291.     set xLoc = xStart
  292.     set yLoc = yStart
  293.     repeat with thisFrame = 1 to nFrames
  294.       set xLoc = integer(xLoc + .49)
  295.       set yLoc = integer(yLoc  + .49)
  296.       set currentFrame = getAt(frameList,relFrameCount)
  297.       add(currentFrame, [#sprite, theCh, castNumTarget, theForeColor, theBackColor, xLoc, yLoc, 0, 0 ])  
  298.       --      mWriteSpriteRange(goScoreMgr, theFrameNum, theCh, castNumTarget, ¼
  299. --                         theForeColor, theBackColor, xLoc, yLoc, 0, 0)    
  300.       setAt(frameList, relFrameCount, currentFrame)
  301.       set theFrameNum = theFrameNum + 1
  302.       set relFrameCount = relFrameCount + 1
  303.       set xLoc = xLoc + xInc
  304.       set yLoc = yLoc + yInc
  305.     end repeat  -- thisFrame
  306.   end repeat   -- thisCycle
  307.   
  308.   mWriteFrame(goScoreMgr, frameList)
  309.   set labelName = "Banners" & goPlatform
  310.   go  label(labelName) + 2  -- to display reselect button
  311.   
  312.   if not(gDevelopmentFlag) then
  313.     tell the stage
  314.       go frame theStageFrame
  315.     end tell
  316.   end if 
  317.   
  318.   mClean(goScoreMgr)
  319.   
  320. end mCreate
  321.  
  322.  
  323.  
  324. on mCleanup me
  325.   global goMotionStyles
  326.   global goSeconds
  327.   global goFPS
  328.   global goBaseLine
  329.   global goDelayEnter
  330.   global goCycles
  331.   global goMarkFrame
  332.   
  333.   mCleanup(goMotionStyles)
  334.   
  335.   set iSaveSeconds =  mGetValue(goSeconds)
  336.   set iSaveFPS = mGetValue(goFPS)
  337.   set iSaveBaseLine = mGetValue(goBaseLine)
  338.   set iSaveDelayEnter = mGetValue(goDelayEnter)
  339.   set iSaveCycles = mGetValue(goCycles)  
  340.   set iSaveMark = mGetValue(goMarkFrame)  
  341.   mCleanup(goMarkFrame)
  342. end mCleanup
  343.  
  344.  
  345.